fix(sema): handle missing Type variants in is_fixed_reference_type#1884
Open
ArshLabs wants to merge 1 commit intohyperledger-solang:mainfrom
Open
fix(sema): handle missing Type variants in is_fixed_reference_type#1884ArshLabs wants to merge 1 commit intohyperledger-solang:mainfrom
ArshLabs wants to merge 1 commit intohyperledger-solang:mainfrom
Conversation
Signed-off-by: Arshdeep Singh <arshdeep.ssingh777@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1882
is_fixed_reference_typepanics withunreachable!when it encountersType::Value, which happens whenmsg.valueis placed inside an array literal and subscripted (e.g.[msg.value][0] <= 0).The array subscript path in
subscript.rscallsarray_ty.deref_memory().is_fixed_reference_type(ns)to decide whether to keep the array pointer or load the value. For an array whose element type isType::Value, this call hits the catch-allunreachable!arm becauseType::Valuewas not listed in the match.Type::Valueis a primitive integer type (is_primitiveandis_integerboth returntruefor it in the same file), so the correct return value isfalse-- it is not a fixed-size reference type.This patch replaces the
unreachable!catch-all with explicit arms for the fiveTypevariants that were missing from the match:Value,Void,Unreachable,BufferPointer, andSorobanHandle. All returnfalsesince none of them are reference types. This also makes the match exhaustive, preventing similar panics if theTypeenum gains new variants in the future.Reproduce:
Before:
thread 'main' panicked at src/sema/types.rs:1427:18After: compiles without error.